const wx2my = require('../../../wx2my');
const Behavior = require('../../../Behavior');
var app = getApp();
Page({
  data: {
    edit: !1
  },
  onLoad: function (e) {
    var u = this;
    u.setData({
      id: e.id
    }), app.getUserInfo(function (e) {
      console.log(e), u.setData({
        userInfo: e,
        scores: Number(e.score)
      });
    }), u.setData({
      color: wx2my.getStorageSync("platform").color
    }), app.util.request({
      url: "entry/wxapp/GoodsDetails",
      cachetime: "0",
      data: {
        id: e.id
      },
      success: function (e) {
        console.log(e), function e(t) {
          var o = t || [];
          var a = Math.round(new Date().getTime() / 1e3);
          var n = o - a || [];
          u.setData({
            clock: (s = n, r = Math.floor(s), c = Math.floor(r / 3600 / 24), i = Math.floor(r / 3600 % 24), l = Math.floor(r / 60 % 60), d = Math.floor(r % 60), c + "天" + i + "小时" + l + "分钟" + d + "秒")
          });
          var s, r, c, i, l, d;
          n <= 0 ? u.setData({
            clock: "已经截止"
          }) : setTimeout(function () {
            n -= 1e3, e(t);
          }, 1e3);
        }(e.data.end_time), u.setData({
          goods_detail: e.data,
          score: Number(e.data.score),
          url: wx2my.getStorageSync("url")
        });
      }
    }), wx2my.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    });
  },
  select_address: function (e) {
    var n = this;
    wx2my.chooseAddress({
      success: function (e) {
        console.log(e);
        var t = e.telNumber,
            o = e.userName,
            a = e.provinceName + e.cityName + e.countyName + e.detailInfo;
        n.setData({
          tel: t,
          name: o,
          address: a,
          edit: !0
        });
      }
    });
  },
  exchange: function (e) {
    var t = this,
        o = t.data.edit,
        a = t.data.goods_detail,
        n = t.data.tel,
        s = t.data.name,
        r = t.data.address,
        c = "";
    if (2 == a.type ? 0 == o ? c = "请选择收货地址" : "" == s || null == s ? c = "请填写姓名" : "" == n || null == n ? c = "请填写联系方式" : "" != r && null != r || (c = "请填写地址") : r = s = n = "", "" != c) wx2my.showModal({
      title: "",
      content: c
    });else {
      var i = wx2my.getStorageSync("userInfo").id,
          l = t.data.id,
          d = a.name,
          u = a.img,
          f = a.score,
          g = a.type,
          m = a.hb_moeny;
      app.util.request({
        url: "entry/wxapp/exchange",
        data: {
          user_id: i,
          good_id: l,
          good_name: d,
          good_img: u,
          user_name: s,
          user_tel: n,
          address: r,
          type: g,
          integral: f,
          hb_money: m
        },
        success: function (e) {
          console.log(e), 1 == e.data ? wx2my.showToast({
            title: "兑换成功"
          }) : wx2my.showToast({
            title: "兑换失败"
          }), setTimeout(function () {
            wx2my.navigateBack({
              delta: 1
            });
          }, 1500);
        }
      });
    }
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {},
  onReachBottom: function () {}
});